package com.davies.learn.feature.supplier;

import java.util.function.Supplier;

/**
 * @author davies
 * @date 2023/8/4 22:31
 */
public class MultiplierImpl implements Multiplier {

    private final int num;

    private final Supplier<Multiplier> supplier;

    public MultiplierImpl(int num,Supplier<Multiplier> supplier) {

        this.num = num;
        this.supplier = supplier;
    }

    @Override
    public String current() {
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= num; i++) {
            sb.append(i).append("X").append(num)
                    .append("=")
                    .append(i * num)
                    .append(" ");
        }
        return sb.toString();
    }

    @Override
    public Multiplier next() {
        System.out.println("冥思苦想....");
        return this.supplier.get();
    }

}
